package com.hyd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hyd.common.annotation.Log;
import com.hyd.common.core.controller.BaseController;
import com.hyd.common.core.domain.AjaxResult;
import com.hyd.common.enums.BusinessType;
import com.hyd.manage.domain.StockAlert;
import com.hyd.manage.service.IStockAlertService;
import com.hyd.common.utils.poi.ExcelUtil;
    import com.hyd.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 药品库存预警Controller
 *
 * @author hwb
 * @date 2025-02-24
 */
@Api(tags = "药品库存预警Controller")
@RestController
@RequestMapping("/manage/alert")
public class StockAlertController extends BaseController
{
    @Autowired
    private IStockAlertService stockAlertService;

    /**
     * 查询药品库存预警列表
     */
    @ApiOperation("查询药品库存预警列表")
    @PreAuthorize("@ss.hasPermi('manage:alert:list')")
    @GetMapping("/list")
    public TableDataInfo list(StockAlert stockAlert)
    {
        startPage();
        List<StockAlert> list = stockAlertService.selectStockAlertList(stockAlert);
        return getDataTable(list);
    }

    /**
     * 导出药品库存预警列表
     */
    @ApiOperation("导出药品库存预警列表")
    @PreAuthorize("@ss.hasPermi('manage:alert:export')")
    @Log(title = "药品库存预警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockAlert stockAlert)
    {
        List<StockAlert> list = stockAlertService.selectStockAlertList(stockAlert);
        ExcelUtil<StockAlert> util = new ExcelUtil<StockAlert>(StockAlert.class);
        util.exportExcel(response, list, "药品库存预警数据");
    }

    /**
     * 获取药品库存预警详细信息
     */
    @ApiOperation("获取药品库存预警详细信息")
    @PreAuthorize("@ss.hasPermi('manage:alert:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stockAlertService.selectStockAlertById(id));
    }

    /**
     * 新增药品库存预警
     */
    @ApiOperation("新增药品库存预警")
    @PreAuthorize("@ss.hasPermi('manage:alert:add')")
    @Log(title = "药品库存预警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockAlert stockAlert)
    {
        return toAjax(stockAlertService.insertStockAlert(stockAlert));
    }

    /**
     * 修改药品库存预警
     */
    @ApiOperation("修改药品库存预警")
    @PreAuthorize("@ss.hasPermi('manage:alert:edit')")
    @Log(title = "药品库存预警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockAlert stockAlert)
    {
        return toAjax(stockAlertService.updateStockAlert(stockAlert));
    }

    /**
     * 删除药品库存预警
     */
    @ApiOperation("删除药品库存预警")
    @PreAuthorize("@ss.hasPermi('manage:alert:remove')")
    @Log(title = "药品库存预警", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockAlertService.deleteStockAlertByIds(ids));
    }
}